﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Security;

namespace NJL.WebManage
{
    public partial class Login : System.Web.UI.Page
    {
        NJL.BLL.NJL_SYS_ADMIN bll = new BLL.NJL_SYS_ADMIN();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (Session["CheckCode"] != null)
            {
                if (txtCheckCode.Text != Session["CheckCode"].ToString())
                {
                    Royalsoft.Common.MessageBox.Show(this, "请输入正确的验证码");
                    return;
                }
            }
            string userName=txtUserName.Text.Trim();
            //string pwd=FormsAuthentication.HashPasswordForStoringInConfigFile(txtPwd.Text,"MD5");
            string pwd = HiddenField1.Value;
            DataSet ds = bll.Login(userName, pwd);
            if (ds.Tables[0].Rows.Count > 0)
            {
                Session.Timeout = 120;
                Session["userid"] = ds.Tables[0].Rows[0]["ID"].ToString();
                Session["username"]= txtUserName.Text;
                Session["usertypecode"] = ds.Tables[0].Rows[0]["TYPE_CODE"].ToString();
                Session["websitecode"]= ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString();

                BLL.NJL_SYS_CS_ADMIN_TYPE bllNJL_SYS_CS_ADMIN_TYPE = new BLL.NJL_SYS_CS_ADMIN_TYPE();
                Model.NJL_SYS_CS_ADMIN_TYPE modelNJL_SYS_CS_ADMIN_TYPE = bllNJL_SYS_CS_ADMIN_TYPE.GetModel(ds.Tables[0].Rows[0]["TYPE_CODE"].ToString());

                BLL.NJL_SYS_BASE bllNJL_SYS_BASE = new BLL.NJL_SYS_BASE();
                Model.NJL_SYS_BASE modelNJL_SYS_BASE = bllNJL_SYS_BASE.GetModel(ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString());
                Session["websitename"] = modelNJL_SYS_BASE.WEBSITE_NAME;
                Session["usertypename"] = modelNJL_SYS_CS_ADMIN_TYPE.TYPE_NAME;


                //Response.Cookies.Add(new HttpCookie("userid", ds.Tables[0].Rows[0]["ID"].ToString()));
                //Response.Cookies.Add(new HttpCookie("username", txtUserName.Text.Trim()));
                //Response.Cookies.Add(new HttpCookie("websitecode", ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString()));
                //Response.Cookies.Add(new HttpCookie("websitename", modelNJL_SYS_BASE.WEBSITE_NAME));
                //Response.Cookies.Add(new HttpCookie("usertypename", modelNJL_SYS_CS_ADMIN_TYPE.TYPE_NAME));

                Response.Redirect("Default.aspx");
            }
            else
            {
                Royalsoft.Common.MessageBox.Show(this, "用户名或密码错误");
            }
        }
    }
}